package cn.edu.cqu.newslab.dao.impl;

import java.util.List;

import cn.edu.cqu.newslab.dao.IUserDao;
import cn.edu.cqu.newslab.model.User;

/**
 * 
 * @ClassName: UserDao
 * @Description: TODO(实现了IUserDao接口，包含对User的数据库操作)
 * @author dongaotong
 * @date 2013-1-5 下午4:35:19
 * 
 */
public class UserDao implements IUserDao {
	
	List users;//模拟用户数据集合

	public List getUsers() {
		return users;
	}

	public void setUsers(List users) {
		this.users = users;
	}

	@Override
	public User findUserByFirstName(String firstName) {
		// TODO Auto-generated method stub
		User user = null;
		int size = this.getUsers().size();
		for( int i =0 ; i < size ; i++){
			user = (User)users.get(i);
			if(firstName.equals(user.getFirstName()))
				return user;
		}
		return null;
	}

	@Override
	public User findUserByLastName(String firstName) {
		// TODO Auto-generated method stub
		User user = null;
		int size = this.getUsers().size();
		for( int i =0 ; i < size ; i++){
			user = (User)users.get(i);
			if(firstName.equals(user.getLastName()))
				return user;
		}
		return null;
	}

	@Override
	public void init() {
		System.out.println("UserDao init...");
		if(1 > users.size()){
			System.out.println("UserDao's users size = 0, init default user --> dong ao tong!");
			users.add(new User("dong ao","tong"));
		}else{
			System.out.println("UserDao init...");	
		}
	}

	@Override
	public void destory() {
		System.out.println("UserDao destory...");		
	}

}
